package main

import (
	"encoding/json"
	"fmt"
)

type Student struct {
	Name string `json:"姓名"`//数字1左边的键
	age int
	Sex string
}

func main(){
	//对数组进行json编码
	x := [5]int{1, 2, 3, 4, 5}
	s, err := json.Marshal(x)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(s))

	//对map进行json编码
	y := make(map[string]float64)
	y["zhangsan"] = 66.66
	s1 ,err1 := json.Marshal(y)
	if err1 != nil {
		panic(err1)
	}

	//fmt.Println(s1)
	fmt.Println(string(s1))


	//对对象进行json编码
	student :=Student{"zhangsan",66,"boy"}

	s2,err2 :=json.Marshal(student)
	if err2 != nil {
		panic(err2)
	}
	fmt.Println(string(s2))

	//对s2进行解码
	var s3 interface{}
	json.Unmarshal([]byte(s2), &s3)
	fmt.Println(s3)

}